package lablayer.model.MathComponents;

import lablayer.model.LabData;

/**
 * @author Darkness
 */

/*
 * Component #9
 *
 * Statistical characteristics of few arrays
 */
class StatisticalCharacteristics implements MathComponent {
	private LabData result;

	private LabData data;

	private String componentName = "Статистические характеристики";

	private String componentId = "9";

	public StatisticalCharacteristics() {
		super();
		this.result = new LabData();
	}
	
	@Override
	public LabData getData() {
		return this.data;
	}

	@Override
	public void calculate() {
		try {
			Double[][] data = (this.data.getData())[0];
			Double[][] result = new Double[data.length][];
			MathComponent middleValue = MathComponentFactory.createMiddleValue();
			MathComponent standardDeviation = MathComponentFactory.createStandardDeviation();
			MathComponent variationCoefficient = MathComponentFactory.createVariationCoefficient();
			MathComponent standardError = MathComponentFactory.createStandardAMSError();

			for (int i = 0; i < data.length; i++) {
				LabData row = new LabData(data[i]);
				middleValue.setData(row);
				standardDeviation.setData(row);
				variationCoefficient.setData(row);
				standardError.setData(row);

				middleValue.calculate();
				standardDeviation.calculate();
				variationCoefficient.calculate();
				standardError.calculate();

				result[i] = new Double[4];
				result[i][0] = (middleValue.getResult().getData())[0][0][0];
				result[i][1] = (standardDeviation.getResult().getData())[0][0][0];
				result[i][2] = (variationCoefficient.getResult().getData())[0][0][0];
				result[i][3] = (standardError.getResult().getData())[0][0][0];
			}

			Double[][][] ret = new Double[1][][];
			ret[0] = result;
			this.result = new LabData(ret);
		} catch (Exception e) {}
	}

	@Override
	public void setData(LabData data) {
		try {
			assert data != null : "";
			this.data = data;
		} catch (NullPointerException e) {}
	}

	@Override
	public String getComponentId() {
		return this.componentId;
	}

	@Override
	public String getComponentName() {
		return this.componentName;
	}

	@Override
	public LabData getResult() {
		return this.result;
	}

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

}
